package com.mail.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mail.dubbo.mapper.UmsAdminRoleRelationMapper;
import com.mail.model.db.UmsAdminRoleRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 吕永乐
 * @date 2022/06/21 17:01
 **/
@DubboService
public class UmsAdminRoleRelationApiImpl implements UmsAdminRoleRelationApi{

	@Autowired
	private UmsAdminRoleRelationMapper umsAdminRoleRelationMapper;

	/**
	 * 根据 adminId 查询
	 *
	 * @param userId
	 * @return
	 */
	@Override
	public List<UmsAdminRoleRelation> getByAdminId(Long userId) {
		LambdaQueryWrapper<UmsAdminRoleRelation> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(userId != null, UmsAdminRoleRelation::getAdminId, userId);
		return umsAdminRoleRelationMapper.selectList(wrapper);
	}

	/**
	 * 批量删除
	 *
	 * @param adminId
	 */
	@Override
	public void removeByAdminId(Long adminId) {
		LambdaQueryWrapper<UmsAdminRoleRelation> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(UmsAdminRoleRelation::getAdminId, adminId);
		umsAdminRoleRelationMapper.delete(wrapper);
	}

	/**
	 * 添加
	 *
	 * @param umsAdminRoleRelation
	 */
	@Override
	public void save(UmsAdminRoleRelation umsAdminRoleRelation) {
		umsAdminRoleRelationMapper.insert(umsAdminRoleRelation);
	}
}
